package com.example.agron.common.utils;


public class APIResponse<T> {
    //是否成功
    private Boolean success;
    //状态码
    private Integer code;
    //提示信息
    private String msg;
    //数据
    private T data;
    public APIResponse() {

    }
    //自定义返回结果的构造方法
    public APIResponse(Boolean success,Integer code, String msg,T data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    //自定义异常返回的结果DefinitionException
    public static APIResponse defineError(){
        APIResponse result = new APIResponse();
        return result;
    }
    //其他异常处理方法返回的结果
    public static APIResponse otherError(ErrorEnum errorEnum){
        APIResponse result = new APIResponse();
        return result;
    }

    public enum ErrorEnum {
        // 数据操作错误定义
        SUCCESS(200, "nice"),
        NO_PERMISSION(403,"你没得权限"),
        NO_AUTH(401,"你能不能先登录一下"),
        NOT_FOUND(404, "未找到该资源!"),
        INTERNAL_SERVER_ERROR(500, "服务器跑路了"),
        ;

        /** 错误码 */
        private Integer errorCode;

        /** 错误信息 */
        private String errorMsg;

        ErrorEnum(Integer errorCode, String errorMsg) {
            this.errorCode = errorCode;
            this.errorMsg = errorMsg;
        }

        public Integer getErrorCode() {
            return errorCode;
        }

        public String getErrorMsg() {
            return errorMsg;
        }
    }
}
